package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.FormatUtil;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.*;
import com.ymttest.utils.YMTDateUtil;

public class ExpWapper {
	SqlManager manage;

	public ExpWapper() {
		manage = new SqlManager("Exp");
	}

	/**
	 * 插入FestivalRateConfig
	 * @param userid
	 * @return
	 */
	public Integer insertFestivalRateConfig(FestivalRateConfig frc){
		Integer i=manage.insert(
				"com.ymttest.database.mapping.ExpMapper.insertFestivalRateConfig", frc);
		manage.commit();
		return i;
	}
	public Integer deleteFestivalRateConfig(String date){
		Map m=new HashMap<>();
		m.put("date", date);
		Integer i=manage.delete(
				"com.ymttest.database.mapping.ExpMapper.deleteFestivalRateConfig", m);
		manage.commit();
		return i;
	}
	public Integer deleteuserexp(int uid){
		Map m=new HashMap<>();
		m.put("uid", uid);
		Integer i=manage.delete(
				"com.ymttest.database.mapping.ExpMapper.deleteuserexp", m);
		manage.commit();
		return i;
	}
	public Integer deleteuserexpdetail(int uid,String bizcode,String bizno,String ono){
		Map m=new HashMap<>();
		m.put("uid", uid);
		m.put("bizcode", bizcode);
		m.put("bizno", bizno);
		m.put("ono", ono);
		Integer i=manage.delete(
				"com.ymttest.database.mapping.ExpMapper.deleteuserexpdetail", m);
		manage.commit();
		return i;
	}
	public List<PrivilegeConfig> selectprivilegeconfig(){
		List<PrivilegeConfig> list=manage.getSelectResults(
				"com.ymttest.database.mapping.ExpMapper.selectprivilegeconfig", null);
		manage.commit();
		return list;
	}
	public Map selectOrderPrice1(){
		List list=manage.getSelectResults(
				"com.ymttest.database.mapping.ExpMapper.selectOrderPrice1", null);
		manage.commit();
		if(list!=null&&!list.isEmpty()){
			return (Map)list.get(0);
		}else{
			return null;
		}
		
	}
	public List<UserExp> selectuserexp(Integer uid){
		Map m=new HashMap<>();
		m.put("uid", uid);
		List<UserExp> list=manage.getSelectResults(
				"com.ymttest.database.mapping.ExpMapper.selectuserexp", m);
		manage.commit();
		return list;
	}
	public List<LevelConfig> selectlevelconfig(Integer lv){
		Map m=new HashMap<>();
		m.put("lv", lv);
		List<LevelConfig> list=manage.getSelectResults(
				"com.ymttest.database.mapping.ExpMapper.selectlevelconfig", m);
		manage.commit();
		return list;
	}
	/**
	 * 查询小于此经验用户数
	 * @param exp
	 * @return
	 */
	public Long selectLtExp(Integer exp){
		Map m=new HashMap<>();
		m.put("exp", exp);
		List<Map> list=manage.getSelectResults(
				"com.ymttest.database.mapping.ExpMapper.selectLtExp", m);
		manage.commit();
		long num=(long) list.get(0).get("num");
		return num;
	}
	public List<UserExpDetail> selectuserexpdetail(Integer uid,String bizcode,String bizno,String ono){
		Map m=new HashMap<>();
		m.put("uid", uid);
		m.put("bizcode", bizcode);
		m.put("bizno", bizno);
		m.put("ono", ono);
		List<UserExpDetail> list=manage.getSelectResults(
				"com.ymttest.database.mapping.ExpMapper.selectuserexpdetail", m);
		manage.commit();
		return list;
	}
	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	
	public static void main(String[] args) {
		FestivalRateConfig frc=new FestivalRateConfig();
		frc.setRate(1d);
		frc.setDate(YMTDateUtil.getSysTime("yyyy-MM-dd"));
		frc.setCreateTime(YMTDateUtil.getDate());
		frc.setEnable(true);
		frc.setRemark("autotest");
		frc.setLastUpdateTime(YMTDateUtil.getDate());
//		System.out.println(new ExpWapper().insertFestivalRateConfig(frc));
//		System.out.println(new ExpWapper().deleteFestivalRateConfig((frc.getDate())));
		System.out.println(FormatUtil.beanToGSONString(new ExpWapper().selectprivilegeconfig()));
		System.out.println(FormatUtil.beanToGSONString(new ExpWapper().selectuserexp(4085)));
		System.out.println(FormatUtil.beanToGSONString(new ExpWapper().selectuserexpdetail(4085,null,null,null)));
	}

	
}
